package com.mht.book.operation.impl;


import com.mht.book.entity.book.Book;
import com.mht.book.entity.book.BookList;
import com.mht.book.operation.Operations;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @author wangfusheng
 * @version 1.0.0
 * @ClassName AddOperation.java
 * @Description TODO
 * @createTime 2022/12/312:30
 */
public class AddOperation implements Operations {
    @Override
    public void work(BookList bookList) {
        System.out.println("新增图书！");
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入图书名称：");
        String name = sc.nextLine();
        System.out.println("请输入图书的作者：");
        String author = sc.nextLine();
        System.out.println("请输入图书类型：");
        String type = sc.nextLine();
        System.out.println("请输入图书的价格：");
        int price = sc.nextInt();
        Book book= new Book(name,author,price,type,false);//实例化一本新书
        //拷贝一份图书信息，进行重新的初始化
        Book[] books = Arrays.copyOf(bookList.getBooks(),bookList.getUsedSize()+1);
        books[bookList.getUsedSize()] = book;
        bookList.setBooks(books);//放置新书
        bookList.setUsedSize(bookList.getUsedSize()+1);//修改书的数量

        System.out.println("恭喜你，图书《"+name+"》新增完成");
        System.out.println();
    }

    //测试方法是否正确
    public static void main(String[] args) {
//        AddOperation addOperation = new AddOperation();
//        addOperation.work(new BookList());

        int x = 8;
        System.out.println((x++)/3);
    }
}
